package main

import (
	"fmt"
	"strconv"
)

// Given two numbers as strings. The numbers may be very large (may not fit in long long int), the task is to find sum of these two numbers.

// Examples:

// Input  : str1 = "3333311111111111",
//          str2 =   "44422222221111"
// Output : 3377733333332222

// Input  : str1 = "7777555511111111",
//          str2 =    "3332222221111"
// Output : 7780887733332222
func addNumber(num1 string, num2 string) string {
	len1, len2 := len(num1), len(num2)
	i, j := len1-1, len2-1
	res := ""
	var carry uint8 = 0
	for i >= 0 || j >= 0 {
		// if i >= 0 && num1[i] == ',' || j >= 0 && num2[j] == ',' {
		// 	i--
		// 	j--
		// 	continue

		// }
		//val1, val2 := 0, 0
		var val1 uint8 = 0
		var val2 uint8 = 0
		//num1[i]-'0', num2[j]-'0'
		if i >= 0 {
			val1 = num1[i] - '0'
		}
		if j >= 0 {
			val2 = num2[j] - '0'
		}
		curValue := (val1 + val2 + carry) % 10
		carry = (val1 + val2 + carry) / 10

		//fmt.Println(carry)
		res = strconv.FormatUint(uint64(curValue), 10) + res
		i--
		j--

	}
	if carry == 1 {
		res = "1" + res
	}
	// fmt.Println(res)
	return res
}
func main() {
	s1 := "7,777,555,511,111,111"
	s2 := "3,332,222,221,111"
	fmt.Println(addNumber(s1, s2))
}
